import axios from "axios"
// Create an instance using the config defaults provided by the library
// At this point the timeout config value is `0` as is the default for the library
const instance = axios.create();

// Override timeout default for the library
// Now all requests using this instance will wait 2.5 seconds before timing out
instance.defaults.timeout = 2500;
// Add a request interceptor
instance.interceptors.request.use(function (config) {
    // Do something before request is sent
    return config;
  }, function (error) {
    // Do something with request error
    return Promise.reject(error);
  });

// Add a response interceptor
instance.interceptors.response.use(function (response) {
    // Do something with response data
    return response;
  }, function (error) {
    switch (error.response.status) {
        case 404:
            console.log('接口不存在')
            break;
        case 400:
            console.log('接口出错了')
            break;
        case 300:
            console.log('接口已被重定向')
            break;
        case 500:
            console.log('服务端错误')
            break;
        case 502:
            console.log('服务器崩溃了')
            break;
        default:
            console.log('未知错误')
            break;
    }
    // Do something with response error
    return Promise.reject(error);
  });
  export default instance